<?php
    $mysqli=new mysqli("localhost","root","root","tb_user");
    if($mysqli->connection_errno){
        die("数据库连接错误！".$mysqli->connection_errno);
    }
    $pass_hash=password_hash($_POST["pass"],PASSWORD_DEFAULT);
    $name=$_POST["name"];

    if(isset($_POST["login"])){
        $sql="SELECT pass_hash FROM tuser WHERE name='$name'";
        $res=$mysqli->query($sql)->fetch_assoc();
        if($res){
            if(password_verify($_POST["pass"],$res["pass_hash"])){
                echo "<script>alert('登录成功！')</script>";
                echo "<script>window.location.href='http://localhost/rhythmgame/start.html'</script>";
            }else{
                echo "<script>alert('密码输入有误！')</script>";
                echo "<script>history.go(-1)</script>";
            }
        }else{
            echo "<script>alert('用户名不存在！')</script>";
            echo "<script>history.go(-1)</script>";
        }
    }
?>